package RedisService;

/**
 * Created by ghost461 on 17-6-28.
 */
import redis.clients.jedis.Jedis;

public class RedisCURD{
    private Jedis jedis;
    public RedisCURD(){
        //连接本地的Redis服务
        jedis = new Jedis("localhost");
        System.out.println("Connection to server sucessfully");
        //查看服务是否运行
        System.out.println("Server is running:"+jedis.ping());
    }
    public void delete(){
        //清空Redis所有数据
        jedis.flushAll();
    }
    public void insert(int num,String information){
        //设置redis字符串数据
        jedis.set(Integer.toString(num),information);
    }
    public String select(int num){
        //获取储存的数据并输出
        return jedis.get(Integer.toString(num));
    }
    public void close(){
        //关闭Redis的连接
        jedis.close();
    }
}
